using System.Collections.Generic;
using Dream.FirstLevel;
using Dream.FirstLevel.Base;
using Dream.FirstLevel.Implement;
using Light;
using Light.Assets.Scripts.EventManager;
using UnityEngine;

namespace Dream.Player
{
    public class Player : MonoBehaviour
    {
        [Header("ProductList的游戏对象")] public ProductList productList;

        /// <summary>
        ///     worker接受到的Product，还没被处理，不能进入UI列表中展示
        /// </summary>
        public List<ProductBase> _waitingProducts = new();

        private void Awake()
        {
            EventManager.Register<ProductCreateEvent>(OnProductCreateEventHandle);
        }

        private void OnDestroy()
        {
            EventManager.Unregister<ProductCreateEvent>(OnProductCreateEventHandle);
        }

        //mao 24-11-25 03:37
        /// <summary>
        ///     根据消息发过来的类型来判断要在ProductList中实例化什么Product脚本
        /// </summary>
        /// <param name="obj"></param>
        private void OnProductCreateEventHandle(ProductCreateEvent obj)
        {
            if (obj.productName == "ProductA")
            {
                ProductA p1 = new(this);
                _waitingProducts.Add(p1);
            }
            else if (obj.productName == "ProductB")
            {
                ProductB p1 = new(this);
                _waitingProducts.Add(p1);
            }
            else
            {
                ProductC p1 = new(this);
                _waitingProducts.Add(p1);
            }
        }
    }
}